package com.jgj.cloud.order.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jgj.cloud.order.entity.Order;
import com.jgj.cloud.order.feign.UserFeignClient;
import com.jgj.cloud.order.mapper.OrderMapper;
import com.jgj.cloud.order.service.OrderService;
import com.jgj.cloud.order.user.emtity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author merat
* @description 针对表【tb_order】的数据库操作Service实现
* @createDate 2025-10-21 11:05:57
*/
@Service
@Slf4j
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order>
    implements OrderService{

    @Autowired
    private OrderMapper orderMapper;

    //代替RestTemplate进行远程调用
    @Autowired
    private UserFeignClient userFeignClient;

    @Override
    public Order findOderByOrderId(Long orderId) {
        //步骤1:根据订单id查询订单信息
        Order order=orderMapper.selectOrderByOrderId(orderId);
        //步骤2:发起远程调用，查询用户信息
        //User user=restTemplate.getForObject("http://my-cloud-user/api/user/findUserById/"+order.getUserId(), User.class);
        User user=userFeignClient.findUserById(order.getUserId());
        //步骤3:将用户信息设置到订单对象中
        order.setUser(user);
        //步骤4::返回订单信息
        return order;
    }

}




